<?php
$auth = Auth::getAuth('current_user');
$db = new Database;
$fs = new functions;
$company_id = $auth['company_id'];
if(isset($_POST['action'])){
	if($_POST['action']=="getForm"){
		//$getForms = $db->query("SELECT * FROM tb_workspace WHERE company_id={$db->escape($auth['company_id'])}","array");
		$getForms = $db->query("SELECT * FROM tb_workspace WHERE is_active={$db->escape(1)} AND company_id = {$db->escape($company_id)}","array");
		$form_json = array();
		foreach($getForms as $form){
			$arr = array("form_id"=>$form['id'],
				     "form_name"=>$form['form_name']);
			array_push($form_json,$arr);
		   
		}
		 echo json_encode($form_json);
	}
	
	// Get Form Fields
	elseif($_POST['action']=="getFlds"){
		$formID = $_POST['formID'];
		
			$getForm_flds = $db->query("SELECT * FROM tb_workspace WHERE id={$db->escape(1)} AND is_active={$db->escape(1)}","row");
			
			$form_flds = $getForm_flds['form_json'];
			
				$decode_flds = json_decode($form_flds, true);
				$fields = $decode_flds['form_fields'];
				$fldName = json_decode($fields, true);
				foreach($fldName as $flds){
					$f = array("fieldName"	=>	 $flds['fieldName']);
					$arr[] = array_diff($f, array("TrackNo", "Requestor", "Status", "Processor",
									"LastAction", "DateCreated", "DateUpdated", "CreatedBy",
									"UpdatedBy", "Unread", "Node_ID", "Workflow_ID"));
				}
					
					echo json_encode(array_filter($arr));
					
			
	}
}
?>